package com.gaogzhen.security.syn;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "security.syn.TestCounter")
public class TestCounter {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 500; i++) {
                counter.increment();
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 500; i++) {
                counter.decrement();
            }
        }, "t2");

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        log.debug("最终计数:{}", counter.getCount());
    }
}
